package com.ct.controller.shipping;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ct.application.commons.vo.StatusRequest;
import com.ct.application.shipping.model.po.ChuanYuanKuShiRenZhengSavePO;
import com.ct.application.shipping.model.po.ChuanYuanKuShiRenZhengSearchPO;
import com.ct.application.shipping.model.vo.ChuanYuanKuShiRenZhengVO;
import com.ct.application.shipping.service.ChuanYuanKuShiRenZhengService;
import com.ct.commons.BaseController;
import com.ct.commons.annotation.ApiLog;
import com.ct.commons.annotation.HasAdmin;
import com.ct.commons.annotation.PermissionApi;
import com.ct.commons.aspect.limiter.AccessIpLimiter;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Objects;

/**
 *  船员证书-适任证配置
 * @author Auto Generator
 * @since 2023-08-16
 */
@RestController
@PermissionApi(title = " 船员证书-适任证",path="/api/v1/chuanyuankushirenzheng",code = "MM1000",sorted = 17)
public class ChuanYuanKuShiRenZhengController extends BaseController {

    @Resource
    private ChuanYuanKuShiRenZhengService chuanYuanKuShiRenZhengService;

    /**
     * 查询 船员证书-适任证列表
     * @param chuanYuanKuShiRenZhengSearchPO
     * @return
     */
    @PostMapping("/chuanyuankushirenzheng/list")
    @PermissionApi(title = "查询 船员证书-适任证列表",path="/api/v1/chuanyuankushirenzheng/list",code = "MM1001",sorted = 1)
    public Page<ChuanYuanKuShiRenZhengVO> findChuanYuanKuShiRenZhengs(@Validated @RequestBody ChuanYuanKuShiRenZhengSearchPO chuanYuanKuShiRenZhengSearchPO) {
        return chuanYuanKuShiRenZhengService.findChuanYuanKuShiRenZheng(chuanYuanKuShiRenZhengSearchPO);
    }

    /**
     * 保存和更新
     *
     * @param savePO
     * @return
     */
    @PostMapping("/chuanyuankushirenzheng/saveupdate")
    @ApiLog(" 船员证书-适任证保存和更新")
    @HasAdmin
    @AccessIpLimiter
    @PermissionApi(title = " 船员证书-适任证保存和更新",path="/api/v1/chuanyuankushirenzheng/saveupdate",code = "MM1003",sorted = 3)
    public ChuanYuanKuShiRenZhengVO saveUpdateChuanYuanKuShiRenZheng(@Validated @RequestBody ChuanYuanKuShiRenZhengSavePO savePO) {
        if (Objects.nonNull(savePO.getId())){
            return chuanYuanKuShiRenZhengService.updateChuanYuanKuShiRenZheng(savePO);
        }else {
            return chuanYuanKuShiRenZhengService.saveChuanYuanKuShiRenZheng(savePO);
        }
    }

    /**
     * 根据id查询 船员证书-适任证
     *
     * @param id
     * @return
     */
    @PostMapping("/chuanyuankushirenzheng/get/{id}")
    @PermissionApi(title = "根据id查询 船员证书-适任证",path="/api/v1/chuanyuankushirenzheng/get/{id}",code = "MM1004",sorted = 4)
    public ChuanYuanKuShiRenZhengVO getChuanYuanKuShiRenZhengById(@PathVariable("id") Long id) {
        return chuanYuanKuShiRenZhengService.getChuanYuanKuShiRenZheng(id);
    }


    /**
     * 根据id删除 船员证书-适任证
     *
     * @param id
     * @return
     */
    @PostMapping("/chuanyuankushirenzheng/del/{id}")
    @ApiLog("根据id删除 船员证书-适任证")
    @HasAdmin
    @AccessIpLimiter
    @PermissionApi(title = "根据id删除 船员证书-适任证",path="/api/v1/chuanyuankushirenzheng/del/{id}",code = "MM1005",sorted = 5)
    public Boolean delChuanYuanKuShiRenZhengById(@PathVariable("id") Long id) {
        return chuanYuanKuShiRenZhengService.delChuanYuanKuShiRenZheng(id);
    }

    /**
     * 修改状态
     *
     * @return
     */
    @PostMapping("/chuanyuankushirenzheng/update/status")
    @ApiLog(" 船员证书-适任证修改状态")
    @HasAdmin
    @AccessIpLimiter
    @PermissionApi(title = " 船员证书-适任证修改状态",path="/api/v1/chuanyuankushirenzheng/update/status",code = "MM1006",sorted = 6)
    public Boolean updateStatus(@Validated @RequestBody StatusRequest statusRequest) {
        return chuanYuanKuShiRenZhengService.updateStatus(statusRequest);
    }
}
